package com.hst.capacity.application.quartz.service.impl;

import cn.smartravel.traffic.alitrip.AlitripCarOpen;
import com.hst.capacity.application.biz.SmsBiz;
import com.hst.capacity.application.biz.VehicleBiz;
import com.hst.capacity.application.quartz.service.VirtualAcceptOrderService;
import com.hst.capacity.domain.common.constants.AliTripTransferConstants;
import com.hst.capacity.domain.common.constants.Constants;
import com.hst.capacity.domain.exception.BusinessException;
import com.hst.capacity.domain.model.entity.order.pool.OrderPoolEntity;
import com.hst.capacity.domain.model.response.driver.DriverInfoVO;
import com.hst.capacity.domain.service.AliTripService;
import com.hst.capacity.domain.service.DriverService;
import com.hst.capacity.domain.service.OrderPoolService;
import com.hst.capacity.infra.persistence.jpa.order.pool.OrderPoolRepository;
import com.hst.capacity.infra.util.DateUtil;
import com.hst.capacity.infra.util.StringUtil;
import com.taobao.api.request.AlitripCarOrderConfirmRequest;
import com.taobao.api.response.AlitripCarOrderConfirmResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Locale;

@Slf4j
@Service
public class VirtualAcceptOrderServiceImpl implements VirtualAcceptOrderService {

    @Autowired
    OrderPoolRepository orderPoolRepository;

    @Autowired
    AliTripService aliTripService;

    @Override
    public void virtualAcceptOrder() {
        log.info("虚拟接单定时器执行开始");

        List<OrderPoolEntity> list = orderPoolRepository.findByStatus(Constants.OrderStatus.ORDER_STATUS_CREATED
        , Integer.parseInt(Constants.Channel.ALITRIP));
        if (list != null && list.size() > 0) {
            for (OrderPoolEntity order : list) {
                try {
                    aliTripService.virtualAcceptAction(order);
                } catch (Exception e) {
                    log.info("虚拟接单出错：{}", e.getMessage());
                }
            }
        }

        log.info("虚拟接单定时器执行结束");
    }

}
